package com.juguo.charginganimation.Adapter;

import android.graphics.drawable.Drawable;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.juguo.charginganimation.Bean.FavoritesListBean;
import com.juguo.charginganimation.R;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.disposables.CompositeDisposable;
import io.supercharge.shimmerlayout.ShimmerLayout;

public class FavoritesGalleryAdapter extends BaseQuickAdapter<FavoritesListBean.Favorites, BaseViewHolder> implements LoadMoreModule {
    private static final String TAG = "cimoBRVAH";
    private CompositeDisposable mDisposable = new CompositeDisposable();
    CheckBox icFavoritesGgbtn;
    List<String> listId = new ArrayList<>();

    public FavoritesGalleryAdapter() {
        super(R.layout.recyclerview_item_favorites);

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, FavoritesListBean.Favorites bean) {

        ShimmerLayout shimmerLayout;
        ImageView imageGalleryItem;
        shimmerLayout = baseViewHolder.getView(R.id.simmeritem);
        imageGalleryItem = baseViewHolder.getView(R.id.imageGalleryitem_favoriter);

        shimmerLayout.setShimmerColor(0X55FFFFFF);
        shimmerLayout.setShimmerAngle(0);
        shimmerLayout.startShimmerAnimation();

        //Glide初始化图片
        Glide.with(baseViewHolder.itemView)
                //加载的URL
                .load(bean.getCoverImgUrl())
                //占位图初始化
                .placeholder(R.color.white)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        //加载成功则停止动画
                        shimmerLayout.stopShimmerAnimation();
                        return false;
                    }
                })
                //装载图片
                .into(imageGalleryItem);
        icFavoritesGgbtn = baseViewHolder.getView(R.id.ic_favorites_ggbtn);
        //选中图片
        icFavoritesGgbtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    listId.add(bean.getId());
                }
            }
        });
    }

    public List<String> getListId() {
        return listId;
    }

}

